#include "StdAfx.h"
#include "SNBasePaintWnd.h"


CSNBasePaintWnd::CSNBasePaintWnd(void)
	: m_hDcPaint(NULL)
	, m_hDcOffscreen(NULL)
	, m_hbmpOffscreen(NULL)
{
	m_bHover = FALSE;
	m_bMouseTracking = FALSE;
	m_bIsMouseOn = FALSE;
	m_hParentDC =FALSE;
	m_bMouseHover = FALSE;
}


CSNBasePaintWnd::~CSNBasePaintWnd(void)
{
	
}

void CSNBasePaintWnd::Init(HWND ahWnd)
{
	if(::IsWindow(ahWnd))
	{
		m_hDcPaint = ::GetDC(ahWnd);
		if (m_hDcPaint)
		{
			RECT loClientRect = {0};
			::GetClientRect(ahWnd, &loClientRect);
			m_hDcOffscreen = ::CreateCompatibleDC(m_hDcPaint);
			m_hbmpOffscreen = ::CreateCompatibleBitmap(m_hDcPaint, (loClientRect.right - loClientRect.left), (loClientRect.bottom - loClientRect.top)); 
		}
	}
}

void CSNBasePaintWnd::UnInit(HWND ahWnd)
{
	if ((m_hDcPaint) && (::IsWindow(ahWnd)))		::ReleaseDC(ahWnd, m_hDcPaint);
	if( m_hDcOffscreen != NULL ) 					::DeleteDC(m_hDcOffscreen);
	if( m_hbmpOffscreen != NULL )					::DeleteObject(m_hbmpOffscreen);
	m_hDcPaint		= NULL;
	m_hDcOffscreen	= NULL;
	m_hbmpOffscreen = NULL;	
}


BOOL CSNBasePaintWnd::TrackMouseLeave( HWND hWnd )
{
	TRACKMOUSEEVENT tme = { 0 };
	tme.cbSize = sizeof(tme);
	tme.dwFlags = TME_LEAVE;
	tme.hwndTrack = hWnd;

	return _TrackMouseEvent(&tme);
}

BOOL CSNBasePaintWnd::TrackMouseHover( HWND hWnd )
{
	TRACKMOUSEEVENT tme = { 0 };
	tme.cbSize = sizeof(tme);
	tme.dwFlags = TME_HOVER;
	tme.hwndTrack = hWnd;

	return _TrackMouseEvent(&tme);
}



void CSNBasePaintWnd::DrawParentWndBg(HWND hWnd, HDC hDC )
{
	if( hWnd == NULL ) return;
	HWND hParentWnd = ::GetParent(hWnd);

	CRect rcWindow;
	::GetWindowRect(hWnd,&rcWindow);
	::ScreenToClient(hParentWnd, (LPPOINT)&rcWindow); 
	::ScreenToClient(hParentWnd, ((LPPOINT)&rcWindow)+1);
	::BitBlt(hDC, 0, 0, rcWindow.Width(), rcWindow.Height(), m_hParentDC, rcWindow.left, rcWindow.top, SRCCOPY);
}